package com.sxkj.web.controller.wechat;

import com.sxkj.common.response.ResponseResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.github.pagehelper.PageInfo;
import com.sxkj.entity.entity.wechat.WechatUser;
import com.sxkj.service.wechat.WechatUserService;

/**
 * @author Zhang Xingliang
 *
 * @description: 微信用户
 * @date 2019-12-25 09:39:56
 */
@RestController
@RequestMapping("/wechat/wechatUser")
public class WechatUserController {

	@Autowired
	private WechatUserService wechatUserService;

	@ApiOperation(value = "根据主键查微信用户信息")
	@GetMapping(value = "/get/{id}")
	public ResponseResult get(@PathVariable String id) {
		try {
			WechatUser wechatUser = wechatUserService.get(id);
			return ResponseResult.success(wechatUser);
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

	@ApiOperation(value = "新增微信用户信息")
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ResponseResult save(@RequestBody WechatUser wechatUser) {
		try {
			wechatUserService.save(wechatUser);
			return ResponseResult.success();
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

	@ApiOperation(value = "删除微信用户信息")
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public ResponseResult delete(@RequestBody WechatUser wechatUser) {
		try {
			wechatUserService.delete(wechatUser);
			return ResponseResult.success();
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

	@ApiOperation(value = "查询微信用户列表")
	@RequestMapping(value = "/findList", method = RequestMethod.POST)
	public ResponseResult findList(@RequestBody WechatUser wechatUser) {
		try {
			return ResponseResult.success(wechatUserService.findList(wechatUser));
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

	@ApiOperation(value = "查询微信用户列表")
	@RequestMapping(value = "/findPage", method = RequestMethod.POST)
	public ResponseResult findPage(@RequestBody WechatUser wechatUser,
			@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
			@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
		try {
			PageInfo pageInfo = wechatUserService.findPage(wechatUser, pageSize, pageNum);
			return ResponseResult.success(pageInfo);
		} catch (Exception e) {
			return ResponseResult.failure(e.toString());
		}
	}

}
